package com.juzi.anli;

import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        //需求：使用方法，支持找出任意整形数组的最大值返回
//        int[] ages = {23, 19, 25, 78, 34};
        int[] ages = new int[5];

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数据：");
        for (int i = 0; i < ages.length; i++) {
            int data = sc.nextInt();
            ages[i] = data;
        }


        int max = getArrayMaxData(ages);
        System.out.println("最大值数据是:" + max);
    }

    public static int getArrayMaxData(int[] arr){
        //找出数组的最大值返回
        int max = arr[0];
        //遍历数组每个元素与最大值进行比较，若最大则替换
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max){
                max = arr[i];
            }
        }
        return max;
    }
}
